<h2>Dispatch Status</h2>
<hr>
<div id="#submitStatus">
</div>
<table id="disburseTable" cellspacing="10" cellpadding="10">
	<tr>
		<th> Sr. No. </th>
		<th> Agent Id </th>
		<th> Agent Name </th>
		<th> Amount </th>
		<th> Transaction Date </th>
		<th> </th>
	</tr>
<?php
	foreach($this->pending as $key => $value){
		echo '<tr id='.$value["ab_trans"].'>';
		echo "<td>".($key+1)."</td>";
		echo "<td>".$value["agent_reg_id"]."</td>";
		echo "<td>".$value["agent_name"]."</td>";
		echo "<td>".$value["amount"]."</td>";
		echo "<td>".$value["trans_date"]."</td>";
		echo "<td>".'<button name="dispatch" tabindex="'.($key+1).'" onclick="javascript:dispatch('.$value["ab_trans"].');">Dispatch</button>'."</td>";
		echo "</tr>";
	}
?>
</table>

<script type="text/javascript" language="javascript">
var urlDispatch = "<?php echo $this->url(array('module'=>'admin','controller' => 'agent', 'action' => 'dispatch'))?>";

function dispatch(trans) {
	$.ajax({
        url : urlDispatch,
        data : {'ab_trans': trans },
        success: function(jStatus){
        	$('#'+trans).hide('slow');
            $( "#submitStatus" ).text(jStatus).show( 'blind', '', 'slow');
        },
            error: function(response) {
          	  $('#errorBox').text(response.responseText).parent().show();
                console.log(response);
                }
            });
}

$(function() {
	$( "button" ).button({
        icons: {
            primary: "ui-icon-check"
        }
    });
});


</script>
